package com.hontech.pastacooking.conn

import com.hontech.pastacooking.app.bus
import com.hontech.pastacooking.event.WeightStatusEvent
import com.hontech.pastacooking.model.WeightStatus
import com.hontech.pastacooking.net.NetClient
import com.hontech.pastacooking.net.REQ_WEIGHT_STATUS


object WeightProto {

    const val OtaStart = 0x02
    const val OtaTranslate = 0x03
    const val OtaComplete = 0x04

    const val Adj = 0x05

    var status = WeightStatus()
        private set

    fun onRecv(frame: Frame) {
        val tmp = WeightStatus()
        frame.parse(
            tmp.appVersion,
            tmp.sensor,
            tmp.inside,
            tmp.external
        )
        bus.post(WeightStatusEvent())
        if (tmp != status) {
            NetClient.notify(REQ_WEIGHT_STATUS, frame.data)
        }
        status = tmp
    }
}